//userMsg.js
const util = require('../../utils/util.js');
let nc;

Page({
  data: {
    ncName: '',
    modifyNickname: false,
    sexName:'',
    modifySex: false,
    dates: '',
    animationData: {},
    animationDatas:{}
  },
  onLoad: function () {
      
  },
  changeHead: function () {
    let that = this;
    wx.showActionSheet({
      itemList: ['拍照', '从手机相册选择'],
      success (res) {
        if (res.tapIndex == 0) {
             wx.chooseImage({
                count: 1, 
                sizeType: ['compressed'], 
                sourceType: ['camera'], 
                success: function(res) {
                  let tempFilePaths = res.tempFilePaths;
                  console.log(tempFilePaths)
                // wx.uploadFile({
                //     url:'', 
                //     filePath: tempFilePaths[0],
                //     name: 'file',
                //     formData:{},
                //     success: function(res){    
                //       let data = JSON.parse(res.data);
                //     }
                //   })
                }
            }) 
        } else {
              wx.chooseImage({
                count: 1, 
                sizeType: ['compressed'], 
                sourceType: ['album'], 
                success: function(res) {
                  let tempFilePaths = res.tempFilePaths;
                  console.log(tempFilePaths)
                // wx.uploadFile({
                //     url:'', 
                //     filePath: tempFilePaths[0],
                //     name: 'file',
                //     formData:{},
                //     success: function(res){    
                //       let data = JSON.parse(res.data);
                //     }
                //   })
                }
            })
        }
      },
      fail (res) {
        console.log(res.errMsg)
      }
    })
  },
  modifyNickname: function () {
    let that = this;
    that.setData({
      modifyNickname: true
      }, () => {
        let animation = wx.createAnimation({
            duration: 500,
            timingFunction: 'ease'
        })
         that.animation = animation 
         setTimeout(function(){
           that.big();
        },200)
    })
  },
  modifyNicknameBoxBtnCancel: function () {
    let that = this;
    that.setData({
      modifyNickname: false
      }, () => {
        let animation = wx.createAnimation({
            duration: 500,
            timingFunction: 'ease'
        })
         that.animation = animation 
         setTimeout(function(){
           that.small();
        },200)
    })
  },
  modifyNicknameClose: function () {
    let that = this;
    that.setData({
      modifyNickname: false
      }, () => {
        let animation = wx.createAnimation({
            duration: 500,
            timingFunction: 'ease'
        })
         that.animation = animation 
         setTimeout(function(){
           that.small();
        },200)
    })
  },
  big: function () {
    let that = this;
    that.animation.scale(1).step()
    that.setData({
      animationData: that.animation.export()
    })
  },
  small: function () {
    let that = this;
    that.animation.scale(0).step()
    that.setData({
      animationData: that.animation.export()
    })
  },
  modifySex: function () {
    let that = this;
    that.setData({
      modifySex: true
      }, () => {
        let animation = wx.createAnimation({
            duration: 500,
            timingFunction: 'ease'
        })
         that.animation = animation 
         setTimeout(function(){
           that.bigs();
        },200)
    })
  },
  modifySexCancel: function () {
    let that = this;
    that.setData({
      modifySex: false
      }, () => {
        let animation = wx.createAnimation({
            duration: 500,
            timingFunction: 'ease'
        })
         that.animation = animation 
         setTimeout(function(){
           that.smalls();
        },200)
    })
  },
  bigs: function () {
    let that = this;
    that.animation.scale(1).step()
    that.setData({
      animationDatas: that.animation.export()
    })
  },
  smalls: function () {
    let that = this;
    that.animation.scale(0).step()
    that.setData({
      animationDatas: that.animation.export()
    })
  },
  nickName: function (e) {
    let that = this;
    nc = e.detail.value;
  },
  defineNmae: function () {
    let that = this;
    if (nc != '') {
      that.setData({
        ncName: nc,
        modifyNickname: false
        }, () => {
          let animation = wx.createAnimation({
              duration: 500,
              timingFunction: 'ease'
          })
          that.animation = animation 
          setTimeout(function(){
            that.small();
          },200)
      })
    }
  },
  chooseSex: function (e) {
    let that = this;
    let sexId = e.currentTarget.dataset.sex;
    if (sexId == 0) {
      that.setData({
        sexName: '男',
        modifySex: false
      }, () => {
        let animation = wx.createAnimation({
            duration: 500,
            timingFunction: 'ease'
        })
         that.animation = animation 
         setTimeout(function(){
           that.smalls();
        },200)
      })
    } else {
      that.setData({
        sexName: '女',
        modifySex: false
      }, () => {
        let animation = wx.createAnimation({
            duration: 500,
            timingFunction: 'ease'
        })
         that.animation = animation 
         setTimeout(function(){
           that.smalls();
        },200)
      })
    }
  },
  modifyBirth: function (e) {
    let that = this;
    that.setData({
      date: e.detail.value
    })
  },
  modifyPhone: function () {
    wx.navigateTo({
       url: '/packageA/pages/modifyphone/modifyphone'
    })
  },
  setPassword: function () {
    wx.navigateTo({
       url: '/packageA/pages/setpassword/setpassword'
    })
  },
  myCode: function () {
    wx.navigateTo({
       url: '/packageA/pages/mycode/mycode'
    })
  },
  logOut: function () {
    wx.showModal({
      title: '',
      content: '确认要退出登录?',
      cancelColor: '#999999',
      confirmColor:'#ff0028',
      success (res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  }
})
